<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%sys_users}}".
 *
 * @property integer $id
 * @property integer $parent_id
 * @property string $phone
 * @property string $parent_phone
 * @property integer $type
 * @property string $password
 * @property integer $role
 * @property integer $last_login_time
 * @property string $truename
 * @property string $qq
 * @property string $qq_openid
 * @property string $email
 * @property string $weixin
 * @property string $wx_openid
 * @property string $tel
 * @property string $company_name
 * @property string $company_addr
 * @property string $company_regnum
 * @property string $company_range
 * @property string $company_spec_range
 * @property string $company_type
 * @property string $company_est_time
 * @property string $company_licence
 * @property integer $reg_time
 * @property integer $status
 */
class SysUsers extends \common\components\activeRecord2015
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%sys_users}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['parent_id', 'type', 'role', 'last_login_time', 'reg_time', 'status','ours'], 'integer'],
            [['phone', 'password'], 'required'],
            [['phone', 'parent_phone'], 'string', 'max' => 11],
            [['password'], 'string', 'max' => 120],
            [['truename', 'qq', 'tel', 'company_type'], 'string', 'max' => 20],
            [['qq_openid', 'wx_openid'], 'string', 'max' => 255],
            [['email', 'weixin'], 'string', 'max' => 50],
            [['company_name', 'company_regnum'], 'string', 'max' => 40],
            [['company_addr', 'company_licence'], 'string', 'max' => 100],
            [['company_range', 'company_spec_range', 'company_est_time','audit'], 'string', 'max' => 500]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'parent_id' => '父账号 ID',
            'phone' => '电话',
            'parent_phone' => '父账号 Phone',
            'type' => 'Type',
            'password' => '密码',
            'role' => '角色',
            'last_login_time' => '最后登录时间',
            'truename' => '名称',
            'qq' => 'QQ',
            'qq_openid' => 'Qq Openid',
            'email' => 'Email',
            'weixin' => '微信',
            'wx_openid' => 'Wx Openid',
            'tel' => 'Tel',
            'company_name' => '公司名称',
            'company_addr' => '公司地址',
            'company_regnum' => '公司注册号',
            'company_range' => 'Company Range',
            'company_spec_range' => 'Company Spec Range',
            'company_type' => '公司类型',
            'company_est_time' => '公司成立时间',
            'company_licence' => '营业执照',
            'reg_time' => '注册时间',
            'status' => '状态',
            'audit'=>'审核信息',
            'ours'=>'是否自营',
        ];
    }
    
    public static function ParentName($parent_id){
           $res = SysUsers::findOne([ 'id' => $parent_id]); 
           $temp = $res['company_name'];         
           return $temp;
    }
    
    public static function getUserName($uid){
        
           $res = SysUsers::findOne([ 'id' => $uid]); 
//           print_r($res['id']);die();
           return $res['company_name'];
    }
    
     public static function getUserPhone($uid){
        
           $res = SysUsers::findOne([ 'id' => $uid]); 
//           print_r($res['id']);die();
           return $res['phone'];
    }
}
